var t = require("../../../@babel/runtime/helpers/toConsumableArray"), a = getApp(), e = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ e ],
    data: {
        show: !1,
        point: {
            lat: "",
            lng: ""
        },
        kwd: "",
        city: "",
        info: [],
        detailinfo: {},
        openDateLw: !1,
        provinceData: [],
        cityData: [],
        districtData: [],
        pickerValue: [ 0, 0, 0 ],
        selectAddressData: [],
        goodsId: "",
        optionsId: "",
        cart_ids: "",
        tag: "",
        total: "",
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        iscloud: ""
    },
    onLoad: function(t) {
        var a = this;
        t.iscloud && this.setData({
            iscloud: t.iscloud
        }), t.ind && this.setData({
            ind: t.ind
        }), this.setData({
            goodsId: t.goodsId,
            optionsId: t.optionsId,
            tag: t.tag,
            total: t.total,
            cart_ids: t.cart_ids,
            level_id: t.level_id,
            option_level_id: t.option_level_id,
            team_id: t.team_id
        }), this._getLocation(function() {
            a.getList();
        }), this._initAddressInfo();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : wx.showToast({
            title: "没有更多数据",
            icon: "none"
        });
    },
    onShareAppMessage: function() {},
    callPhone: function(t) {
        var a = t.currentTarget.dataset.phone;
        wx.makePhoneCall({
            phoneNumber: a
        });
    },
    showDetail: function(t) {
        var a = t.currentTarget.dataset.v;
        this.setData({
            show: !0,
            detailinfo: a
        });
    },
    onClose: function() {
        this.setData({
            show: !1,
            detailinfo: {}
        });
    },
    getList: function() {
        var t = this, e = a.getNetAddresss("plugin.package-deliver.frontend.deliver.getList");
        (this.options.store_id || this.options.groupStoreID) && (e = a.getNetAddresss("plugin.package-deliver.frontend.store.deliver.getList"));
        var i = a.qqMapTransBMap(parseFloat(t.data.point.lng), parseFloat(t.data.point.lat));
        a._getNetWork({
            url: e,
            data: {
                city_name: t.data.city,
                lat: i.lat,
                lng: i.lng,
                kwd: t.data.kwd,
                goods: t.options.goods || [],
                store_id: this.options.store_id || this.options.groupStoreID || ""
            },
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.setData({
                    info: e.data.list.data,
                    total_page: e.data.list.last_page,
                    isLoadMore: !0,
                    page: e.data.list.current_page
                }), t.data.total_page || t.setData({
                    total_page: 0
                })) : wx.showToast({
                    icon: "none",
                    title: "获取自提点失败",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var e = this;
        if (this.setData({
            isLoadMore: !1
        }), !(this.data.page >= this.data.total_page)) {
            var i = this.data.page;
            i += 1, this.setData({
                page: i
            });
            var o = a.qqMapTransBMap(parseFloat(e.data.point.lng), parseFloat(e.data.point.lat)), s = a.getNetAddresss("plugin.package-deliver.frontend.deliver.getList");
            (this.options.store_id || this.options.groupStoreID) && (s = a.getNetAddresss("plugin.package-deliver.frontend.store.deliver.getList")), 
            a._getNetWork({
                url: s,
                data: {
                    city_name: e.data.city,
                    lat: o.lat,
                    lng: o.lng,
                    kwd: e.data.kwd,
                    page: e.data.page,
                    goods: e.options.goods || [],
                    store_id: this.options.store_id || this.options.groupStoreID || ""
                },
                success: function(a) {
                    var i = a.data;
                    if (1 == i.result) {
                        var o = i.data.list.data, s = [].concat(t(e.data.info), t(o));
                        e.setData({
                            info: s,
                            total_page: i.data.list.last_page
                        });
                    }
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        }
    },
    openDateLwtbtn: function() {
        this.setData({
            openDateLw: !0
        });
    },
    _initAddressInfo: function() {
        var t = this;
        wx.getStorage({
            key: "provinceData",
            success: function(a) {
                console.log("地址信息准备就绪"), t._getProvinceData();
            },
            fail: function(e) {
                console.log("省fail"), a._getNetWork({
                    url: a.getNetAddresss("member.member-address.address"),
                    success: function(a) {
                        var e = a.data, i = e.data.province, o = e.data.city, s = e.data.district;
                        wx.setStorage({
                            key: "provinceData",
                            data: i
                        }), wx.setStorage({
                            key: "cityData",
                            data: o
                        }), wx.setStorage({
                            key: "districtData",
                            data: s
                        }), t._initAddressInfo();
                    },
                    fail: function(t) {},
                    state: !0
                });
            }
        });
    },
    _getProvinceData: function() {
        var t = this;
        wx.getStorage({
            key: "provinceData",
            success: function(a) {
                console.log("省读取成功", a.data), t.setData({
                    provinceData: a.data
                }), t.setData({
                    "selectAddressData[0].name": a.data[t.data.pickerValue[0]].areaname,
                    "selectAddressData[0].id": a.data[t.data.pickerValue[0]].id,
                    "selectAddressData[0].index": t.data.pickerValue[0]
                }), t._getCityData();
            }
        });
    },
    _getCityData: function() {
        var t = this.data.selectAddressData[0];
        console.log("城市", "_data", t);
        var a = this;
        wx.getStorage({
            key: "cityData",
            success: function(e) {
                console.log("城市读取成功", e);
                for (var i = [], o = 0; o < e.data.length; o++) e.data[o].parentid == t.id && i.push(e.data[o]);
                console.log("城市数据筛选", i), a.setData({
                    cityData: i
                }), a.setData({
                    "selectAddressData[1].name": i[a.data.pickerValue[1]].areaname,
                    "selectAddressData[1].id": i[a.data.pickerValue[1]].id,
                    "selectAddressData[1].index": a.data.pickerValue[1]
                }), a._getDistrictData();
            }
        });
    },
    _getDistrictData: function() {
        var t = this.data.selectAddressData[1];
        console.log("地区", "_data", t), console.log(t);
        var a = this;
        wx.getStorage({
            key: "districtData",
            success: function(e) {
                console.log("地区读取成功");
                for (var i = [], o = 0; o < e.data.length; o++) e.data[o].parentid == t.id && i.push(e.data[o]);
                console.log("地区数据筛选", i), a.setData({
                    districtData: i
                }), console.log("districtData", i), a.setData({
                    "selectAddressData[2].name": i[a.data.pickerValue[2]].areaname,
                    "selectAddressData[2].id": i[a.data.pickerValue[2]].id,
                    "selectAddressData[2].index": a.data.pickerValue[2]
                }), console.log("over", a.data.selectAddressData);
            }
        });
    },
    bindChange: function(t) {
        var a = t.detail.value;
        this.data.pickerValue[0] != a[0] && (a[1] = 0, a[2] = 0), this.data.pickerValue[1] != a[1] && (a[2] = 0), 
        this.setData({
            "pickerValue[0]": a[0],
            "pickerValue[1]": a[1],
            "pickerValue[2]": a[2]
        }), this._initAddressInfo();
    },
    _okAddress: function() {
        var t = this.data.selectAddressData;
        this.setData({
            city: t[1].name
        }), this.getList(), this._closeDateLw();
    },
    _closeDateLw: function() {
        this.setData({
            openDateLw: !1
        });
    },
    tosearch: function(t) {
        var a = t.detail.value;
        this.setData({
            kwd: a
        }), this.getList();
    },
    gotoOrder: function() {
        this.getNowPackageDeliver(this.data.detailinfo.id);
        var t = {
            deliver_name: this.data.detailinfo.deliver_name,
            deliver_mobile: this.data.detailinfo.deliver_mobile,
            full_address: this.data.detailinfo.full_address,
            id: this.data.detailinfo.id
        }, e = JSON.stringify(t), i = "/packageD/buy/myOrder_v2/myOrder_v2?from=1&tag=" + this.data.tag + "&goodsId=" + this.data.goodsId + "&optionsId=" + this.data.optionsId + "&total=" + this.data.total + "&changeSelfCarry=" + e;
        this.data.cart_ids && (i = i + "&cart_ids=" + this.data.cart_ids), this.data.level_id && (i = i + "&level_id=" + this.data.level_id + "&option_level_id=" + this.data.option_level_id), 
        this.data.team_id && (i = i + "&team_id=" + this.data.team_id + "&option_level_id=" + this.data.option_level_id), 
        this.options.goodCollection && (i = i + "&goodCollection=" + this.options.goodCollection), 
        this.data.ind && (i = i + "&ind=" + this.data.ind), this.options.store_id && Number(this.options.store_id) > 0 && (i = i + "&store_id=" + this.options.store_id), 
        this.options.groupStoreID && (i = i + "&groupStoreID=" + this.options.groupStoreID), 
        this.options.plu && (i = i + "&plu=" + this.options.plu), this.options.exchangeData && (i = i + "&exchangeData=" + this.options.exchangeData), 
        a._isTextEmpty(this.data.iscloud) ? wx.redirectTo({
            url: i
        }) : wx.redirectTo({
            url: "/packageE/others/cloudwarehouse/cloudOrder/cloudOrder?from=1&tag=" + this.data.tag + "&goodsId=" + this.data.goodsId + "&optionsId=" + this.data.optionsId + "&total=" + this.data.total + "&changeSelfCarry=" + e + "&is_selected=8"
        });
    },
    getNowPackageDeliver: function(t) {
        var e = a.getNetAddresss("plugin.package-deliver.frontend.decorate-deliver.getNowPackageDeliver");
        a._postNetWork({
            url: e,
            data: {
                deliver_id: t
            },
            success: function(t) {
                var a = t.data;
                1 == a.result ? (wx.getStorageSync("deliverId") || null) && wx.setStorageSync("deliverId", a.data.id) : wx.showToast({
                    title: a.msg,
                    duration: 1e3,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    }
});